/*
 * Copyright (C) 2011 Urals State University,
 * Department of Mathematics and Mechanics
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package ru.edu.usu.cs.bubbles.engine.box2d;

import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.Body;
import com.badlogic.gdx.physics.box2d.BodyDef;
import com.badlogic.gdx.physics.box2d.Fixture;
import com.badlogic.gdx.physics.box2d.FixtureDef;
import com.badlogic.gdx.physics.box2d.PolygonShape;

import ru.edu.usu.cs.bubbles.engine.Fish;
import ru.edu.usu.cs.bubbles.engine.box2d.colliders.Collider;
import ru.edu.usu.cs.bubbles.utils.Point;

public class Box2dFish extends Fish implements Box2dEntity {
	private Collider collider = null;
	private Body fishBody;
	
	private static final Vector2[] defaultFishVertices = {
		new Vector2(0, 1),
		new Vector2(0, 2),
		new Vector2(1, 3),   
		new Vector2(4, 3),
		new Vector2(5, 2),
		new Vector2(5, 1),
		new Vector2(4, 0),
		new Vector2(1, 0)
	};
	
	protected Box2dFish(Body body, float angle) {
		fishBody = body;
		
		PolygonShape fishShape = new PolygonShape();
		Vector2[] fishVertices = new Vector2[defaultFishVertices.length];
		for(int i = 0; i < defaultFishVertices.length; ++i)
			fishVertices[i] = defaultFishVertices[i].rotate(angle);
		fishShape.set(fishVertices);
		
		FixtureDef wallFixtureDef = new FixtureDef();
		wallFixtureDef.shape = fishShape;
		Fixture fanFixture = fishBody.createFixture(wallFixtureDef);
		fanFixture.setGameEntity(this);
		fishShape.dispose();
		
		fishBody.setType(BodyDef.BodyType.KinematicBody);
	}
	
	@Override
	public float getAngle() {
		return fishBody.getAngle();
	}

	@Override
	public int getSize() {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public Point getPosition() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Body getBody() {
		// TODO Auto-generated method stub
		return null;
	}
	
	@Override
	public Collider getCollider() {
		return collider;
	}

	@Override
	public void setCollider(Collider collider) {
		this.collider = collider;
	}

}
